package com.caishi.lkx.user.service.impl;

import com.caishi.lkx.user.mapper.AgentRechargeMapper;
import com.caishi.lkx.user.model.AgentRechargeModel;
import com.caishi.lkx.user.service.IAgentRechargeService;
import com.caishi.lkx.user.service.IAgentUserService;
import com.zzw.common.entity.IBaseMapper;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
* @Author: huangpeng
* @Date: 2021/9/23 9:37
* @Description:
*/
@Service
@Slf4j
public class AgentRechargeServiceImpl implements IAgentRechargeService {
@Resource
private AgentRechargeMapper agentRechargeMapper;
@Resource
private IAgentUserService agentUserService;

    @Override
    public IBaseMapper<AgentRechargeModel, String> getMapper() {
        return agentRechargeMapper;
    }


    @Override
    @Transactional(rollbackFor = Exception.class)
    public AgentRechargeModel insert(AgentRechargeModel entity) {
        if(getMapper().insert(entity) == 1){
            agentUserService.recharge(entity.getUserId(),entity.getAmount(),entity.getType());
        }
        return entity;
    }
}
